using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Gueei.Gallery.Core.Entities;
using Gueei.Gallery.Core.Repositories;
using Gueei.Gallery.Core.Services;
using Gueei.Gallery.JsonRepositories;
using Gueei.Gallery.Web.Services;
using Ninject;
using Ninject.Mvc3;

//[assembly: WebActivator.PreApplicationStartMethod(typeof(Gueei.Gallery.Web.AppStart_NinjectMVC3), "Start")]

namespace Gueei.Gallery.Web {
    public static class AppStart_NinjectMVC3 {
        public static void RegisterServices(IKernel kernel)
        {
        	kernel.Bind<ReindexService>().To(typeof (ReindexService)).InSingletonScope();
        	kernel.Bind<IDisplayProfileRepository>().To(typeof(DefaultDisplayProfileRepository)).InSingletonScope();
        	kernel.Bind<IImageRepository>().To(typeof (JsonImageRepository))
        		.InSingletonScope()
        		.WithConstructorArgument("jsonDir", Settings.Settings.FileDirectory);
        	kernel.Bind<ITagRepository>().To(typeof (JsonTagRepository))
        		.InSingletonScope()
        		.WithConstructorArgument("jsonDir", Settings.Settings.FileDirectory);
        	kernel.Bind<IImageService>().To(typeof (CachedThumbnailImageService))
        		.InSingletonScope()
        		.WithConstructorArgument("localCachePath", Settings.Settings.CacheDirectory);

        	kernel.Bind<IAlbumRepository>().To(typeof (JsonAlbumRepository))
        		.InSingletonScope()
        		.WithConstructorArgument("jsonDir", Settings.Settings.FileDirectory);

        	kernel.Bind<BatchImportService>().To(typeof (BatchImportService))
        		.InSingletonScope()
        		.WithConstructorArgument("tempStoragePath", Settings.Settings.TempDirectory);
        	kernel.Bind<IFileRepository>().To(typeof (LocalFileRepository))
        		.InSingletonScope()
        		.WithConstructorArgument("localPath", Settings.Settings.FileDirectory);
        	kernel.Bind<AlbumService>().To(typeof (AlbumService)).InSingletonScope();
        	kernel.Bind<IUserService>().To(typeof (WebUserService)).InSingletonScope();
        }

        public static void Start() {
            // Create Ninject DI Kernel 
            IKernel kernel = new StandardKernel();

            // Register services with our Ninject DI Container
            RegisterServices(kernel);

            // Tell ASP.NET MVC 3 to use our Ninject DI Container 
            DependencyResolver.SetResolver(new NinjectServiceLocator(kernel));
        }
    }
}
